home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Pascal / Libraries / GrafSys 2.0 / GrafSys 2.0 source / TriangleFill Pascal Code < prev    next >
Encoding:
Text File  |  1993-07-26  |  1.6 KB  |  67 lines  |  [TEXT/PJMM]

  1.  
  2. (* Top-Down :    Pascal version of the triangle top-down fill algorithm *)
  3. (*                    just provided to test and demonstrate the algorithm *)
  4. (*                    calling convention :     b is highest point, a and d have same     *)
  5. (*                                            vertical component                         *)
  6.  
  7. procedure TPTopDown (a, b, d: point);
  8.     var
  9.         deltaxleft, deltaxright: fixed;
  10.         dx, dy: integer;
  11.         ys, ye: integer;
  12.         xs, xe: fixed;
  13.  
  14. begin
  15.     dy := a.v - b.v;
  16.     dx := a.h - b.h;
  17.     deltaXleft := FixRatio(dx, dy); (* ATTN: dy may be zero ! *)
  18.     dx := d.h - b.h;
  19.     deltaXright := FixRatio(dx, dy);
  20. (* Not implemented : plot b itself *)
  21.     xs := FixRatio(b.h, 1);
  22.     ys := b.v;
  23.     xe := FixRatio(b.h, 1);
  24.     ye := b.v; (* now both point to the start point *)
  25.     while ye < a.v do
  26.         begin (* go down one line and plot from s to e horizontal line *)
  27.             ys := ys + 1;
  28.             ye := ye + 1;
  29.             xs := xs + deltaXleft;
  30.             xe := xe + deltaXright;
  31.             MoveTo(HiWord(xs), ys);
  32.             LineTo(HiWord(xe), ye);
  33.         end;
  34. end;
  35.  
  36.  
  37. procedure TPBottomUp (a, d, c: point);
  38.  
  39.     var
  40.         deltaxleft, deltaxright: fixed;
  41.         dx, dy: integer;
  42.         ys, ye: integer;
  43.         xs, xe: fixed;
  44.  
  45.  
  46. begin
  47.     dy := a.v - c.v;
  48.     dx := a.h - c.h;
  49.     deltaXleft := FixRatio(dx, dy); (* ATTN: dy may be zero ! *)
  50.     dx := d.h - c.h;
  51.     deltaXright := FixRatio(dx, dy);
  52. (* Not implemented : plot b itself *)
  53.     xs := FixRatio(c.h, 1);
  54.     ys := c.v;
  55.     xe := FixRatio(c.h, 1);
  56.     ye := c.v; (* now both point to the start point *)
  57.     while ye > a.v do
  58.         begin (* go down one line and plot from s to e horizontal line *)
  59.             ys := ys - 1;
  60.             ye := ye - 1;
  61.             xs := xs - deltaXleft;
  62.             xe := xe - deltaXright;
  63.             MoveTo(HiWord(xs), ys);
  64.             LineTo(HiWord(xe), ye);
  65.         end;
  66. end;
  67.